From e2c0a9d84c8664d1e67e76d812a7ed259ac1bc64 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 14 Apr 2015 01:50:00 -0500 Subject: [PATCH] pass `-C ar`/`-C linker` when building native dylibs/plugins closes #1515 --- src/cargo/ops/cargo_rustc/mod.rs | 19 ++++++------ tests/test_cargo_compile_plugins.rs | 48 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 5617135d9..3a4863abf 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -694,21 +694,22 @@ fn build_base_args(cx: &Context, fn build_plugin_args(cmd: &mut CommandPrototype, cx: &Context, pkg: &Package, target: &Target, kind: Kind) { + fn opt(cmd: &mut CommandPrototype, key: &str, prefix: &str, + val: Option<&str>) { + if let Some(val) = val { + cmd.arg(key).arg(&format!("{}{}", prefix, val)); + } + } + cmd.arg("--out-dir").arg(&cx.out_dir(pkg, kind, target)); cmd.arg("--emit=dep-info,link"); if kind == Kind::Target { - fn opt(cmd: &mut CommandPrototype, key: &str, prefix: &str, - val: Option<&str>) { - if let Some(val) = val { - cmd.arg(key).arg(&format!("{}{}", prefix, val)); - } - } - opt(cmd, "--target", "", cx.requested_target()); - opt(cmd, "-C", "ar=", cx.ar(kind)); - opt(cmd, "-C", "linker=", cx.linker(kind)); } + + opt(cmd, "-C", "ar=", cx.ar(kind)); + opt(cmd, "-C", "linker=", cx.linker(kind)); } fn build_deps_args(cmd: &mut CommandPrototype, diff --git a/tests/test_cargo_compile_plugins.rs b/tests/test_cargo_compile_plugins.rs index f293968fa..e5c4e979a 100644 --- a/tests/test_cargo_compile_plugins.rs +++ b/tests/test_cargo_compile_plugins.rs @@ -2,6 +2,7 @@ use std::fs; use std::env; use support::{project, execs}; +use support::{COMPILING, RUNNING}; use hamcrest::assert_that; fn setup() { @@ -219,3 +220,50 @@ test!(doctest_a_plugin { assert_that(p.cargo_process("test").arg("-v"), execs().with_status(0)); }); + +// See #1515 +test!(native_plugin_dependency_with_custom_ar_linker { + let (_, target) = ::cargo::ops::rustc_version().unwrap(); + + let foo = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [lib] + name = "foo" + plugin = true + "#) + .file("src/lib.rs", ""); + + let bar = project("bar") + .file("Cargo.toml", r#" + [package] + name = "bar" + version = "0.0.1" + authors = [] + + [lib] + name = "bar" + + [dependencies.foo] + path = "../foo" + "#) + .file("src/lib", "") + .file(".cargo/config", &format!(r#" + [target.{}] + ar = "ar" + linker = "cc" + "#, target)); + + foo.build(); + assert_that(bar.cargo_process("build").arg("--verbose"), + execs().with_stdout(&format!("\ +{compiling} foo v0.0.1 ({url}) +{running} `rustc [..] -C ar=ar -C linker=cc [..]` +{compiling} bar v0.0.1 ({url}) +{running} `rustc [..] -C ar=ar -C linker=cc [..]` +", compiling = COMPILING, running = RUNNING, url = bar.url()))) +}); -- 2.30.2